<template>
    <el-form :model="model" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
        <el-row>
            <el-col :span="8">
                <el-form-item label="供应商编码" prop="VendorCode">
                    <el-input v-model="model.VendorCode"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="供应商名称" prop="VendorName">
                    <el-input v-model="model.VendorName"></el-input>
                </el-form-item>

            </el-col>
            <el-col :span="8">
                <el-form-item label="供应商简称" prop="VendorNick">
                    <el-input v-model="model.VendorNick"></el-input>
                </el-form-item>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="8">
                <el-form-item label="客户英文名称" prop="VendorEn">
                    <el-input v-model="model.VendorEn"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="供应商简介" prop="VendorDes">
                    <el-input v-model="model.VendorDes"></el-input>
                </el-form-item>

            </el-col>
            <el-col :span="8">
                <el-form-item label="供应商地址" prop="Address">
                    <el-input v-model="model.Address"></el-input>
                </el-form-item>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="8">
                <el-form-item label="供应商等级" prop="VendorLevel">
                    <el-select v-model="model.VendorLevel">
                        <el-option label="优质供应商" value="优质供应商"></el-option>
                        <el-option label="正常" value="正常"></el-option>
                        <el-option label="重点关注" value="重点关注"></el-option>
                        <el-option label="劣质供应商" value="劣质供应商"></el-option>
                        <el-option label="黑名单" value="黑名单"></el-option>
                    </el-select>

                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="供应商评分" prop="VendorScore">
                    <el-rate v-model="model.VendorScore"></el-rate>
                </el-form-item>

            </el-col>
            <el-col :span="8">
                <el-form-item label="供应商官网" prop="Website">
                    <el-input v-model="model.Website"></el-input>
                </el-form-item>
            </el-col>

        </el-row>
        <el-row>
            <el-col :span="8">
                <el-form-item label="供应商邮箱地址" prop="Email">
                    <el-input v-model="model.Email"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="供应商电话" prop="Tel">
                    <el-input v-model="model.Tel"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="联系人1-姓名" prop="Contact1">
                    <el-input v-model="model.Contact1"></el-input>
                </el-form-item>
            </el-col>

        </el-row>
        <el-row>
            <el-col :span="8">
                <el-form-item label="联系人1-电话" prop="Contact1Tel">
                    <el-input v-model="model.Contact1Tel"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="联系人1-邮箱" prop="ProcessId">
                    <el-input v-model="model.ProcessId"></el-input>
                </el-form-item>

            </el-col>
            <el-col :span="8">
                <el-form-item label="联系人2-姓名" prop="Contact2">
                    <el-input v-model="model.Contact2"></el-input>
                </el-form-item>
            </el-col>

        </el-row>
        <el-row>
            <el-col :span="8">
                <el-form-item label="联系人2-电话" prop="Contact2Tel">
                    <el-input v-model="model.Contact2Tel"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="联系人2-邮箱" prop="Contact2Email">
                    <el-input v-model="model.Contact2Email"></el-input>
                </el-form-item>

            </el-col>
            <el-col :span="8">
                <el-form-item label="社会信用代码" prop="CreditCode">
                    <el-input v-model="model.CreditCode"></el-input>
                </el-form-item>
            </el-col>

        </el-row>
        <el-row>
            <el-col :span="8">
                <el-form-item label="备注" prop="Remark">
                    <el-input v-model="model.Remark"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="8">
                <el-form-item label="是否启用" prop="EnableFlag">
                    <el-radio-group v-model="model.EnableFlag">
                        <el-radio label="Y">是</el-radio>
                        <el-radio label="N">否</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-col>


        </el-row>
        <div class="page-form-action">
            <el-button type="primary" @click="submitForm">{{ isUpdate ? '立即保存' : '立即创建' }}</el-button>
            <el-button @click="resetForm">重置</el-button>
        </div>

    </el-form>

</template>
<script>
export default {
   
    props: {
        model: {
            require: true,
            type: Object
        },
        isUpdate: {
            require: true,
            type: Boolean,
        }
    },
    data() {
        return {
            VendorList:[],
            rules: {
                VendorCode: { required: true, message: '请输入供货商编码', trigger: 'blur' },
                VendorName: { required: true, message: '请输入供货商名称', trigger: 'blur' },
            }


        }
    },
    created(){
        this.getVendorAll();
    },
    methods:{
        submitForm(){
            this.$refs['ruleForm'].validate((valid)=>{
          if(valid){
          if(this.isUpdate){
            this.put();
          }else{
            this.add();
          }
          }else{
            this.showNotify('请输入必填项');
            return false;
          }
        });
        },
      resetForm(){
        this.$refs['ruleForm'].resetFields();
      },
      add(){
        this.$http.postForm('/api/Vendor',{model:this.model},{loading:this.$loading()})
        .then(()=>{
          this.$emit('callback');
        })
      },
      put(){
        this.$http.putForm('/api/Vendor',{model:this.model},{loading:this.$loading()})
        .then(()=>{
          this.$emit('callback');
        })
      },
      getVendorAll(){
        this.$http.get('/api/Vendor/GetAll')
        .then(res=>{
            this.VendorList=res.Data;
        })
      }
    }
}
</script>